package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymatou.iapi.godmch.parameter.getDepotListByMchIdBean;
import com.ymatou.iapi.godmch.service.createDepotCall;
import com.ymatou.iapi.godmch.service.getDepotListByMchIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.database.model.godmch.mch_depot_infoExample;
import com.ymttest.database.sqlwapper.godmch.mch_depot_infoWapper;
/**
*查询商户仓库信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getDepotListByMchId{
	private static getDepotListByMchIdBean bean;
	private static getDepotListByMchIdCall call;
	
	
	createDepotBean cbean=new createDepotBean ();
	createDepotCall ccall=new createDepotCall();
    	
	mch_depot_infoWapper depotWapper;
	mch_depot_infoExample example;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询商户仓库信息");
	}

	@Before
	public void caseUp() {
		bean=new getDepotListByMchIdBean();
		call=new getDepotListByMchIdCall();
		
		
		depotWapper=new mch_depot_infoWapper();
		example=new mch_depot_infoExample();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void check_verify() throws InterruptedException {
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		
		example.clear();
		example.createCriteria().andMchIdEqualTo(bean.getMchId());
        List<mch_depot_info> lst=depotWapper.selectByExample(example);
        List<mch_depot_info> return_depots=call.getDepots();
        int count=0;
        for(mch_depot_info DB_depot:lst)
        {
        	Logger.comment("验证DepotId："+DB_depot.getDepotId());
        	Logger.verifyEquals(return_depots.get(count).getDepotId(), DB_depot.getDepotId(), "验证第"+(count+1)+"个数据库字段DepotId与返回的是否一致");
        	Logger.verifyEquals(return_depots.get(count).getDepotTitle(), DB_depot.getDepotTitle(), "验证第"+(count+1)+"个数据库字段DepotTitle与返回的是否一致");
        	
        	//新增 20200619
        	Logger.verifyEquals(return_depots.get(count).getBuyerTitle(), DB_depot.getBuyerTitle(), "验证第"+count+"个数据库字段BuyerTitle与传入的是否一致");
        	Logger.verifyEquals(return_depots.get(count).getPicUrl(), DB_depot.getPicUrl(), "验证第"+count+"个数据库字段PicUrl与传入的是否一致");
        	
        	count++;
        }
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotListByMchId_001() {
		Logger.start(true,"查询商户仓库信息--验证商户1条仓库");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);

			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			
			check_verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotListByMchId_001_1() {
		Logger.start(true,"查询商户仓库信息--验证存在的商户2条仓库");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			GodmchManageCallService.createDepot(mchId);

			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();			
			check_verify();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotListByMchId_002_1() {
		Logger.start(true,"查询商户仓库信息--验证商户的仓库为空");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			bean.setMchId(mchId);
			call.setData(bean);
			call.callService();		

			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true,call.getDepots().size()==0, "验证Depots为空");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotListByMchId_002() {
		Logger.start(true,"查询商户仓库信息--验证不存在的商户Id");
		try {

			bean.setMchId(999999);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true,call.getDepots().size()==0, "验证Depots为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotListByMchId_003() {
		Logger.start(true,"查询商户仓库信息--验证商户Id为空");
		try {
			
			call.setData(bean);
			call.callService();				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}